package com.qianqu.module_finding.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.qianqu.module_finding.R;
import com.qianqu.module_finding.adapter.viewholder.TimeViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * ${description}
 *
 * @author weiqiliu
 * @version 1.0 2018/7/11
 */
public class TabAdapter extends RecyclerView.Adapter<TimeViewHolder> {
    private Context activity;
    private int selectPosition=0;
    private List<String> timeList=new ArrayList<>();

    public TabAdapter(Context activity, List<String> timeList) {
        this.activity = activity;
        this.selectPosition = selectPosition;
        this.timeList = timeList;
    }

    @Override
    public TimeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        RecyclerView.ViewHolder viewHolder = null;
        View view;
        view = LayoutInflater.from(activity).inflate(R.layout.item_time, parent, false);
        return new TimeViewHolder(view);
    }

    @SuppressLint("ResourceAsColor")
    @Override
    public void onBindViewHolder(TimeViewHolder holder, final int position) {
        holder.textView.setText(timeList.get(position));
        holder.textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectPosition=position;
                notifyDataSetChanged();
            }
        });

        if (position == selectPosition) {
            holder.textView.setBackgroundColor(0xFFFF0000);
            holder.textView.setTextColor(0xFFFFFFFF);
        } else {
            holder.textView.setBackgroundColor(0xFFFF00FF);
            holder.textView.setTextColor(0xFFFFFF00);
        }
    }

    @Override
    public int getItemCount() {
        return timeList.size();
    }

}
